package ipad.asia.controller;

import ipad.asia.dao.PunishEnterpriseDao;
import ipad.asia.entity.PunishConsumer;
import ipad.asia.entity.PunishEnterprise;
import ipad.asia.service.PunishEnterpriseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;
@RestController
public class PunishEnterpriseController {
    @Autowired
    private PunishEnterpriseService punishEnterpriseService;
    @Autowired
    private PunishEnterpriseDao punishEnterpriseDao;
    /**
     * 获取所有的被投诉商家
     * @return
     */
    @RequestMapping("/admin/complaintEnterprise/getAll")
    public List<PunishEnterprise> findAll(){
        return punishEnterpriseService.findAll();
    }

    @RequestMapping("/admin/complaintEnterprise/getById")
    public PunishEnterprise findById(@RequestParam(value = "id") int id){
        return punishEnterpriseService.findById(id);
    }
    /**
     * 查看当前商铺的所有投诉
     * @param
     * @return
     */
    @RequestMapping("/admin/complaintEnterprise/getByShopId")
    public List<PunishEnterprise> findByShopId(@RequestParam(value = "shopId") int shopId){
        return punishEnterpriseService.findByShopId(shopId);
    }
    /**
     * 对被投诉的人做出处罚，不要轻易做出处罚，处罚一次，警告一次，第二次严重警告，第三次封号
     * @param
     */
    @RequestMapping("/admin/waringEnterprise")
    public void waring(@RequestParam(value = "shopId") int shopId){
        punishEnterpriseService.waring(shopId);
    }
    /**
     * 投诉商家
     * @param
     * @param reason
     * @param proof
     * @param reportEmail
     * @param date
     */
    @RequestMapping("/complaint/enterprise")
    public void complaintConsumer(@RequestParam(value = "shopId",required = false)int shopId,
                                  @RequestParam(value = "shopName",required = false)String shopName,
                                  @RequestParam(value = "reason",required = false)String reason,
                                  @RequestParam(value = "proof",required = false)String proof,
                                  @RequestParam(value = "reportEmail",required = false)String reportEmail,
                                  @RequestParam(value = "date",required = false)LocalDateTime date){
        PunishEnterprise punishEnterprise=new PunishEnterprise();
        punishEnterprise.setShopId(shopId).setProof(proof).setReason(reason).
                setShopName(shopName).setReportEmail(reportEmail).setDate(date);
        punishEnterpriseService.save(punishEnterprise);
    }
    @RequestMapping("/shop/update")
    @Transactional
    public void update(@RequestParam(value = "statues",required = false) int statues,
                       @RequestParam(value = "serious",required = false)int serious,
                       @RequestParam(value = "result",required = false)String result,
                       @RequestParam(value = "id",required = false)int id){
        punishEnterpriseDao.update(statues, serious,result, id);
    }
}
